/**
 * Created by oneminute on 7/17/14.
 */

var lz = require("../lib/utils/modules")();

exports.get = function (_req, _res, _opts, _callback) {
    var user = _req.user;
    var did = _req.query.nid;
    if (!user) {
        lz.Logger.warn("/topneed: 用户为临时用户。");
        _callback(lz.Config.errors.getError(lz.Config.errors.REQUEST_TEMPUSER_ERROR));
        return;
    }
    var demand = new lz.Demand({id: did});
    demand.load({method: "byId"}, function (_err, _demand) {
        user.topItem("demands", _demand._id, function (_err, _user) {
            if (_err) {
                lz.Logger.error("/topdemand: 置顶失败。");
                _callback(_err, user);
            } else {
                lz.Logger.debug("/topdemand: 置顶成功。");
                _callback(null, user);
            }
        });
    });
};